#include "Field.h"

#ifndef ZERO
	#define ZERO 0
#endif

#ifndef MAX_SIZE_CAMPO
	#define MAX_SIZE_CAMPO 200
#endif

//---------------------------------------------------------------------------------------------------------------------
//	IMPLEMENTATION OF CLASS Field
//---------------------------------------------------------------------------------------------------------------------

Field::Field()
	:ID(ZERO),
	name(""),
	type(ZERO),
	size(ZERO)
{
}

Field::Field(const Field &toCopy)
{
	ID = toCopy.ID;
	name = toCopy.name;
	type = toCopy.type;
	size = toCopy.size;
}

Field::~Field()
{
	ID = ZERO;
	name.clear();
	type = ZERO;
	size = ZERO;
}

void Field::set(int id, campo *campo)
{
	
	ID = id;
	if( campo != NULL)
	{
		name.clear();
		name += campo->nombre;
		type = campo->tipo;
		size = campo->longitud;	
	}
}

void Field::get(int &id, campo *campo)
{
	id = ID;
	if( campo != NULL)
	{
		memcpy((char*)campo->nombre, name.c_str(), name.size());
		campo->tipo = type;
		campo->longitud = size;	
	}
	
}

int Field::getID()
{
	return ID;
}

const Field & Field::operator=(const Field &toAssign)
{
	if(this != &toAssign)
	{
		ID = toAssign.ID;
		name = toAssign.name;
		type = toAssign.type;
		size = toAssign.size;
	}
	return *this;
}

void Field::print()
{
	std::cout << "FIELD: " << std::endl;
	std::cout << "ID: " << ID << std::endl;
	std::cout << "name: " << name.c_str() << std::endl;
	std::cout << "type: " << type << std::endl;
	std::cout << "size: " << size << std::endl;
}
